package cn.wolfcode.car.business.service.impl;

import cn.wolfcode.car.business.domain.Goods;
import cn.wolfcode.car.business.domain.Store;
import cn.wolfcode.car.business.mapper.StoreMapper;
import cn.wolfcode.car.business.query.StoreQuery;
import cn.wolfcode.car.business.service.IStoreService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.exception.BusinessException;
import cn.wolfcode.car.shiro.ShiroUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class StoreServiceImpl implements IStoreService {

    @Autowired
    private StoreMapper storeMapper;



    @Override
    public TablePageInfo<Store> query(StoreQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<Store>(storeMapper.selectForList(qo));
    }


    @Override
    public void save(Store store) {
        // 新增操作
        storeMapper.insert(store);
    }

    @Override
    public Store get(Long id) {
        return storeMapper.selectByPrimaryKey(id);
    }



    @Override
    public List<Store> list() {
        return storeMapper.selectAll();
    }

    @Override
    public void update(Store store) {
        storeMapper.updateByPrimaryKey(store);
    }

    @Override
    public void delete(Long ids) {
        List<Goods> goods = storeMapper.selectGoodsByStoreId(ids);
        if (goods.size() ==0) {
            storeMapper.deleteByPrimaryKey(ids);
        }else{
            throw new BusinessException("仓库还有物品,不能删除哦~");
        }

    }


}
